import Mock from "mockjs";
const color = require("./index.json");
import dataJson from "./mock.json";
const data = Mock.mock({
  "list|25": [
    {
      id: "@increment()",
      type: "@cword(3,5)",
      name: "@cname",
      "all|500-550": 0,
      "number|5-10": 0,
      "limit|600-650": 0,
      time: "@now()",
      "status|1": [true, false],
      line: "@cword(4,6)",
      startDate: "@date",
      startLocation: "@city()",
      endLocation: "@city()",
      startTime: "@time()",
      endTime: "@time()",
      checked: false,
      far: "10:00",
      "submitStatus|1": ["已提交", "未提交"],
      carone: "G34",
      cartype: "高铁",
      "softsleeper|60-80": 1,
      "hardsleeper|100-180": 1,
      "orderNum|555555-9999999": 1,
      name: "@cname(2,4)",
      phone: "12312431423",
      "payStatus|1": ["已支付", "已取消", "已取票"],
      "types|1": ["商务座", "一等座", "二等座"],
      "num|20-30": 2,
      "prices|400-500": 0,
      carcar: "02车09A号",
      "sitType|1": ["商务座", "一等座", "二等座"],
    },
  ],
});

const ticket = Mock.mock({
  "list|3": [
    {
      "type|1": ["商务座", "一等座", "二等座"],
      "num|20-30": 2,
      "price|400-500": 2,
    },
  ],
});
Mock.mock(RegExp("/getList" + ".*"), (req, res) => {
  return {
    data: data.list,
  };
});

Mock.mock(RegExp("/getCityCar" + ".*"), (req, res) => {
  console.log(req.url);
  const type = req.url.split("=")[1];
  switch (type) {
    case "day":
      return null;
    case "week":
      return color[1];
    case "month":
      return color[2];
    default:
      break;
  }
  return {
    type,
  };
});

Mock.mock(RegExp("/search" + ".*"), (req) => {
  console.log(req.url);
  const ipt = req.url.split("&")[0].split("=")[1];
  const date = req.url.split("date=")[1];
  return dataJson.filter((item) => item.idCard === ipt && item.date === date);
});

Mock.mock("/api/ticketList", (req, res) => {
  return {
    data: ticket.list,
  };
});
